//
//  FZOAuthView.swift
//  FZSina_Swift
//
//  Created by 李忠 on 7/20/16.
//  Copyright © 2016 FZLZ. All rights reserved.
//

import UIKit

class FZOAuthProgressView: UIProgressView {

    var timer: NSTimer?
    var isAnim: Bool = true
    
    override init(frame: CGRect) {
        super.init(frame: CGRect(x: 0, y: 64.0, width: SCREENW, height: 5.0))
        self.tintColor = UIColor.blueColor()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:从父类删除
    func removeFu(){
        
        removeFromSuperview()
        timer?.invalidate()
        timer = nil
        
    }

//MARK:==========================动画==========================
    func startAnim() {
        progress = 0.0
        self.hidden = false
        self.hidden = false
        timer = NSTimer.scheduledTimerWithTimeInterval(0.05, target: self, selector: #selector(valueChange), userInfo: nil, repeats: true)
    }
    //开始动画
    func valueChange()  {
        if isAnim {
            progress += 0.05
            if progress == 0.95 {
                return
            }
        }else{
            if progress == 1.0 {
                timer?.invalidate()
                self.hidden = true
            }else{
                progress += 0.5
            }
        }
    }
    //结束动画
    func stopAnim() {
        
        isAnim = false
    }
    deinit{
        
        
    }
    
}
